import 'package:flame/components.dart';

abstract class ScaleSpriteComponent extends SpriteComponent {
  late double spriteRadio;
  final Vector2 setPosition;
  double setWidth;
  String src;
  double tOpacity;
  bool scaleFit;
  Vector2? fixedSize;
  double? setAngle;

  ScaleSpriteComponent(
    this.setWidth,
    this.setPosition,
    this.src, {
    this.tOpacity = 1,
    this.scaleFit = true,
    this.fixedSize,
    this.setAngle,
  });

  @override
  Future<void> onLoad() async {
    angle = setAngle ?? 0;
    sprite = await Sprite.load(src);
    position = setPosition;
    spriteRadio = sprite!.image.width / sprite!.image.height;
    if (scaleFit) {
      size = Vector2(setWidth, setWidth / spriteRadio);
    } else {
      size = fixedSize!;
    }
    opacity = tOpacity;
  }
}
